<?php

namespace plugin\admin\app\controller\Crontab;

use think\facade\Db;

class Task
{
    public function clearCronLog(){
        $task = config('plugin.yzh52521.task.app.task');
        if($task){
            abort(1001,'配置不存在，请安装相应插件');
        }
        $res = Db::table($task['crontab_table_log'])->whereWeek('create_time', 'last week')->delete();
        return $res;
    }
    public function disk(){
        $dirPath = runtime_path() . '/logs/';
        $disk_size                = floor(disk_total_space($dirPath) / (1024 * 1024)) .'MB';

        $path = runtime_path() . '/logs/admin';
        $filesize = 0;
        $filearr = [];
        $iterator = new \FilesystemIterator($path);

        foreach($iterator as $entry) {
            $filearr[]['name'] = $entry->getFilename();
            $filearr[]['size'] = $entry->getSize();
            $filesize += $entry->getSize();
        }
        $resData = [
            '$disk_size'=>$disk_size,
            '$filearr'=>$filearr,
            '$filesize'=>$filesize,
        ];
        return $resData;
    }
}